package com.kefu.chat.smart.condition;

import java.util.List;

import com.google.common.collect.Lists;
import com.kefu.chat.smart.ChatConnectCondition;
import com.kefu.chat.vo.ChatUserParam.UserConnectP;
import com.kefu.chat.vo.ChatUserParam.UserConnectR;
import com.kefu.common.trigger.Condition;
import com.kefu.common.trigger.Decision;
import com.kefu.common.trigger.TriggerWrapper;
import com.kefu.common.trigger.model.ConditionModel;
import com.kefu.common.trigger.model.DynamicModel;
import com.kefu.common.trigger.model.DynamicModel.OptionType;
import com.kefu.common.trigger.model.DynamicModel.SearchType;

//@Component
public class ChatEnterpriseCondition implements ChatConnectCondition<Integer> {

	@Override
	public String getCode() {
		return "enterprise";
	}

	@Override
	public ConditionModel getConditionModel() {
		DynamicModel<ConditionModel> dynamicModel=DynamicModel.<ConditionModel>builder()
										.url("crm/enterprise/tree")
										.code("id")
										.name("name")
										.searchType(SearchType.Tree)
										.build();
		return ConditionModel.builder()
				.code(getCode())
				.name(getMessageName())
				.decisions(Lists.newArrayList(Decision.EQ,Decision.NE,Decision.IS_NULL,Decision.IS_NOT_NULL))
				.optionType(OptionType.Simple)
				.dynamicModel(dynamicModel)
				.build();
	}

	@Override
	public String getName() {
		return "公司";
	}

	@Override
	public boolean match(TriggerWrapper<UserConnectP, UserConnectR> wrapper, Condition condition) {
		List<String> list=getOperatorList(condition);
		return getCustomer(wrapper)!=null&&condition.getDecision().match(list, getCustomer(wrapper).getEnterpriseId(),null);
	}

}
